$(function() {
	var ManageLogined = {
		createNew: function() {
			var managelogined = {};
			managelogined.init = function() {
				this.initData();
				this.bindEvent();
			};
			managelogined.initData = function() {
				
				$.ajax({
					type: "GET",
					url: CONFIGER_MANAGER.DOMAIN + "ajax_query_merchant_info" + "?u_id=" + getLocalStorage(STORATE_MANAGER.user).u_id,
					async: false,
					dataType: "JSON"
				}).done(function(data) {
					if (data.success) {
						thisPage.paintHtml(data.data);
					} else {
						$.toast(data.error_msg);
					}

				}).fail(function(data) {
					console.log(data);
				}).always(function() {
					
				});


				//		    $.get(
				//		    "http://121.41.6.183:9999/ajax_query_merchant_info",
				//		    {},
				//		    function(data) {
				//		    },
				//		    "json"
				//		    );


			};
			managelogined.bindEvent = function() {

			};
			managelogined.paintHtml = function(data) {
				var html = [];
				/*--------------------------------公司基本信息----------------------------------*/
				var merchant = data.merchant_info;
				html.push('<li><span>企业名称：</span><span class="graycolor_9">' + merchant.merchant_name + '</span></li>');
				html.push('<li><span>注册账号：</span><span class="graycolor_9">' + merchant.register_account + '</span></li>');
				html.push('<li><span>注册地址：</span><span class="graycolor_9">' + merchant.register_address + '</span></li>');
				html.push('<li><span>办公地址：</span><span class="graycolor_9">' + merchant.office_address + '</span></li>');
				$("ul#merchant").html(html.join(''));
				/*--------------------------------联系人信息----------------------------------*/
				var contact = data.contact_info;
				html = [];
				html.push('<li><span>姓名：</span><span class="graycolor_9">' + contact.contact_person + '</span></li>');
				html.push('<li><span>手机号：</span><span class="graycolor_9">' + contact.mobile_no + '</span></li>');
				html.push('<li><span>职务：</span><span class="graycolor_9">' + contact.position + '</span></li>');
				html.push('<li><span>QQ号：</span><span class="graycolor_9">' + contact.qq + '</span></li>');
				html.push('<li><span>邮箱：</span><span class="graycolor_9">' + contact.mail + '</span></li>');
				html.push('<li><span>固定电话：</span><span class="graycolor_9">' + contact.telephone + '</span></li>');
				$("ul#contact").html(html.join(''))
					/*--------------------------------账户信息----------------------------------*/
				var account = data.account_info;
				html = [];
				html.push('<h4 style="margin-top: 0px;">余额明细&nbsp;&nbsp;<span class="px10">账户余额：&yen' + account.amount + '元</span></h4>');
				html.push('<P class="graycolor_9"><span class="redcolorB10319">●</span>充值金额：' + account.deposit_amount + '元</P>');
				html.push('<P class="graycolor_9"><span class="redcolorFF9600">●</span>消费金额：' + account.consume_amount + '元</P>');
				html.push('<P class="graycolor_9">历史充值次数：' + account.deposit_amount + '次</P>');
				$("#account").html(html.join(''));


				/*-----------------------------------一年消费------------------------------------*/
				var yearConsumeChart = echarts.init(document.getElementById('yearconsumeinfo'));
				var yearconsumeinfo = account.year_consume_info;
				
				/*对象排序begin*/
				function sortDate(a, b){
					return a - b
				}				
				var i = 0;
				var keyArray = [];
				var newArray = [];
				for (var key in yearconsumeinfo){
					if(key.length == 6){
						var dateArray = key.split("-");
						key = dateArray[0] + '-0' +  dateArray[1]
					}					
					var date = Date.parse(key);
					var newDate = new Date(date);
					keyArray.push(newDate);
				}
				keyArray.sort(sortDate);
				while (keyArray[i]){
					newArray.push( keyArray[i].Format('yyyy-M')  );
					i++;
				}
				/*对象排序end*/
				
				var month = [];
				var yearconsumevalue = [];
				var yearconumeMaxValue = 0;
				i = 0;
				while (newArray[i]){
					month.push(newArray[i]);
					yearconsumevalue.push(yearconsumeinfo[newArray[i]]);					
					i++;
				}				
				
				option = {
					tooltip: {
						trigger: 'item',
						formatter:'{b}月浏览{c}次'
					},
					calculable: true,
					xAxis: [{
						type: 'category',
						boundaryGap: false,
						data: month,
						axisLabel:{interval:0}
					}],
					yAxis: [{
						type: 'value',
					}],
					series: [{
						type: 'line',
						barWidth:10,
						data: yearconsumevalue
					}]
				};
				yearConsumeChart.setOption(option);				
				/*----------------------------------历史消费-------------------------------------*/
				var historyConsumeChart = echarts.init(document.getElementById('hisconsumeinfo'));
				var hisconsumeinfo = data.his_browse_info;
				$("#sumconsumecount").html(hisconsumeinfo['sum']);
				delete hisconsumeinfo['sum'];
				month = [];
				var hisConsumevalue = [];
				
				keyArray = [];
				newArray = [];
				for (var key in hisconsumeinfo){
					if(key.length == 6){
						var dateArray = key.split("-");
						key = dateArray[0] + '-0' +  dateArray[1]
					}
					var date = Date.parse(key);
					var newDate = new Date(date);
					keyArray.push(newDate);
				}
				keyArray.sort(sortDate);
				i=0;
				while (keyArray[i]){
					newArray.push( keyArray[i].Format('yyyy-M')  );
					i++;
				}
				i=0;
				while (newArray[i]){
					month.push(newArray[i]);
					hisConsumevalue.push(hisconsumeinfo[newArray[i]]);					
					i++;
				}	
				
				option = {
					tooltip: {
						trigger: 'item',
						formatter:'{b}月浏览{c}次'
					},
					calculable: true,
					xAxis: [{
						type: 'category',
						boundaryGap: false,
						data: month,
					}],
					yAxis: [{
						type: 'value',
					}],
					series: [{
						type: 'line',
						data: hisConsumevalue
					}]
				};
				historyConsumeChart.setOption(option);




			};

			return managelogined;
		},
	}

	var thisPage = ManageLogined.createNew();
	thisPage.init();
});